package start.demo01.datatype.json.interfaces;

import start.demo01.datatype.json.entity.editor.stringEditor.Replace;
import start.demo01.datatype.json.entity.editor.stringEditor.StringToJSON;
import start.demo01.datatype.json.entity.editor.stringEditor.Truncation;
import start.demo01.datatype.json.pool.CacheMap;

public abstract class StringEditor implements Editor {

    protected String args;
    protected String name;
    protected CacheMap map;

    @Override
    public void setMap(CacheMap map) {
        this.map = map;
    }

    public StringEditor(String name, String cmd) {
        this.name = name;
        args=cmd.substring(cmd.indexOf('(')+1,cmd.lastIndexOf(')'));
    }

    public static StringEditor builder(String cmd) {
        String[] arr = Editor.getName(cmd);
        cmd = arr[1];
        if (cmd.startsWith("strToJSON")) {
            return new StringToJSON(arr[0], cmd);
        } else if (cmd.startsWith("truncation")) {
            return new Truncation(arr[0], cmd);
        } else if (cmd.startsWith("replace"))
            return new Replace(arr[0], cmd);
        return null;
    }
}
